﻿using System;
using System.Collections.Specialized;

namespace Heimdallr.Net
{
    /// <summary>
    /// Provides data for the <see cref="HttpMultipartSplitter.PartReceived"/> event.
    /// </summary>
    public class PartReceivedEventArgs : EventArgs
    {
        #region Field

        private readonly NameValueCollection headers;
        private readonly byte[] data;
        private readonly object userState;

        #endregion

        #region Property

        /// <summary>
        /// Get the headers of current part.
        /// </summary>
        public NameValueCollection Headers
        {
            get { return this.headers; }
        }

        /// <summary>
        /// Get the byte array of the body of current part.
        /// </summary>
        public byte[] Body
        {
            get { return this.data; }
        }

        /// <summary>
        /// Gets a value that represents the user state.
        /// </summary>
        public object UserState
        {
            get { return this.userState; }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the PartReceivedEventArgs class.
        /// </summary>
        /// <param name="headers">The headers of current part.</param>
        /// <param name="body">The byte array of the body of current part.</param>
        /// <exception cref="ArgumentNullException">Paramenter <see cref="headers"/> or <see cref="body"/> is null.</exception>
        public PartReceivedEventArgs(NameValueCollection headers, byte[] body)
            : this(headers, body, null)
        {
        }

        /// <summary>
        /// Initializes a new instance of the PartReceivedEventArgs class.
        /// </summary>
        /// <param name="headers">The headers of current part.</param>
        /// <param name="body">The byte array of the body of current part.</param>
        /// <param name="userState">A value that represents the user state.</param>
        /// <exception cref="ArgumentNullException">Paramenter <see cref="headers"/> or <see cref="body"/> is null.</exception>
        public PartReceivedEventArgs(NameValueCollection headers, byte[] body, object userState)
        {
            if (headers == null)
                throw new ArgumentNullException("headers");

            if (body == null)
                throw new ArgumentNullException("body"); 

            this.headers = headers;
            this.data = body;
            this.userState = userState;
        }

        #endregion
    }
}
